package org.lex.checksum.utils;

import java.io.File;
import java.util.Comparator;

public class FileNameComparator implements Comparator<File> {
	private static final FileNameComparator instance = new FileNameComparator();

	public static FileNameComparator getInstance() {
		return instance;
	}

	public int compare(File f1, File f2) {
		if (f1 == f2)
			return 0;
		if (null == f1)
			return null == f2 ? 0 : 1;
		if (null == f2)// now f1 != null && f2 == null
			return -1;
		boolean aIsFolder = ((File) f1).isDirectory();
		if (aIsFolder != ((File) f2).isDirectory())
			return aIsFolder ? 1 : -1;
		return ((File) f1).compareTo((File) f2);
	}
}
